﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OracleClient;

namespace Projekt_GUI.Forms
{
    public partial class Erweiterungen : Form
    {
        public Erweiterungen()
        {
            InitializeComponent();
        }

        private void Erweiterungen_Load(object sender, EventArgs e)
        {
            Refresh();
        }

        public void Refresh()
        {
            using (OracleConnection con = new OracleConnection("Data Source=localhost; User Id=PROJEKT; Password=PROJEKT"))
            {
                con.Open();
                OracleCommand com = con.CreateCommand();
                com.CommandText = "SELECT Name, Preis, Nummer FROM Erweiterungen";

                OracleDataReader r = com.ExecuteReader();

                int counter = 0;
                listView1.Items.Clear();
                while (r.Read())
                {
                    listView1.Items.Add(r.GetValue(0).ToString());
                    listView1.Items[counter].SubItems.Add(r.GetValue(1).ToString() + "€");
                    listView1.Items[counter].SubItems.Add(r.GetValue(2).ToString());
                    counter++;
                }
            }
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                Form1.CartExt.Add((Form1.CartExt.Count + 1).ToString(), listView1.SelectedItems[0].SubItems[2].Text);
                MessageBox.Show("Die Erweiterung wurde dem Warenkorb hinzugefügt.", "Warenkorb", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
}
